#!/bin/zsh

# 开启显示命令,用于调式.
# set -x
# 存放build文件路径.
filePath="$1"
pattern="static int sdkBuild"

#提取build号.
# build=`awk '/static int sdkBuild/ {print $5}' ${filePath}`
# eval的扫描时,$4,会直接用当前变量替换,如果要保留,用\\$5来保留.
# \"会被替换为\,即转义字符会替换.
# 变量会替换.
build=`eval "awk '/${pattern}/ {print \\$5}' ${filePath}"`
# build=eval "awk '/${pattern}/ {print \$5}' ${filePath}"

echo "latest build is:${build}"

# 去掉;
build=${build/;}

# 去掉"
build=${build//\"}
# echo "last build is: ${build}"
build=$((++build))
eval "sed -i \"\" 's/${pattern} = .*/${pattern} = ${build};/' ${filePath}"
[[ $? != 0 ]] && echo "update failed" && exit -1
echo "current build is: ${build}"

